package edu.kaist.cs408.pof.backend.service;

import edu.kaist.cs408.pof.backend.dao.RestaurantDaoImpl;
import edu.kaist.cs408.pof.backend.dao.UserDaoImpl;
import edu.kaist.cs408.pof.common.model.RestaurantOwnerVo;
import edu.kaist.cs408.pof.common.model.RestaurantVo;
import edu.kaist.cs408.pof.common.service.RestaurantOwnerSvc;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;

import javax.ws.rs.QueryParam;

/**
 * Created with IntelliJ IDEA.
 * User: duyleekun
 * Date: 5/11/12
 * Time: 1:20 AM
 * To change this template use File | Settings | File Templates.
 */
@Configurable
public class RestaurantOwnerSvcImpl implements RestaurantOwnerSvc {

	@Autowired
	UserDaoImpl userDao;

	@Autowired(required = true)
	RestaurantDaoImpl restaurantDao;

	@Override
	public RestaurantOwnerVo create(RestaurantOwnerVo newUser) {
		return userDao.createRestaurantOwner(newUser);
	}

	@Override
	public RestaurantOwnerVo login(@QueryParam("username") String username, @QueryParam("password") String password) {
		RestaurantOwnerVo thisUser = userDao.findRestaurantOwner(username);
		if (thisUser.getPassword().equals(password))
			return thisUser;
		else
			return null;
	}

	@Override
	public RestaurantOwnerVo setRestaurant(RestaurantVo newRestaurant, @QueryParam("owner") ObjectId owner) {
		restaurantDao.createRestaurant(newRestaurant);
		return userDao.setRestaurant(owner, newRestaurant.getMid());
	}
}
